home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.StyleChat / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  4.8 KB  |  216 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TEXTSERVICES__
  53. #include "TextServices.h"
  54. #endif
  55.  
  56. #ifndef __TOOLUTILS__
  57. #include <ToolUtils.h>
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. /*****************************************************************************/
  67.  
  68.  
  69.  
  70. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  71.  
  72.  
  73.  
  74. /*****************************************************************************/
  75. /*****************************************************************************/
  76.  
  77.  
  78.  
  79. /* Do the right thing for an event.  Determine what kind of event it is, and
  80. ** call the appropriate routines. */
  81.  
  82. #pragma segment Main
  83. void    DoEvent(EventRecord *event)
  84. {
  85.     WindowPtr    window, oldPort;
  86.     Point        pt;
  87.     OSErr        err;
  88.     TEHandle    teHndl;
  89.     Rect        rct;
  90.  
  91.     switch(event->what) {
  92.  
  93.         case nullEvent:
  94.             DoIdleTasks(event);
  95.             break;
  96.  
  97.         case mouseDown:
  98.             DoMouseDown(event);
  99.             break;
  100.  
  101.         case autoKey:
  102.         case keyDown:                    /* Check for menukey equivalents. */
  103.             DoKeyDown(event);
  104.             break;
  105.  
  106.         case activateEvt:
  107.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  108.             DoActivate((WindowPtr)event->message);
  109.             if (TSMTEAvailable()) TSMEvent(event);
  110.             break;
  111.  
  112.         case updateEvt:
  113.             DoUpdate((WindowPtr)event->message);
  114.             break;
  115.  
  116.         case kHighLevelEvent:
  117.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  118.             DoHighLevelEvent(event);
  119.             break;
  120.  
  121.         case osEvt:
  122.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  123.             switch ((event->message >> 24) & 0xFF) {
  124.                     /* Must logical and with 0xFF to get only low byte. */
  125.                     /* High byte of message. */
  126.  
  127.                 case mouseMovedMessage:
  128.                     DoIdleTasks(event);
  129.                     break;
  130.  
  131.                 case suspendResumeMessage:
  132.                         /* Suspend/resume is also an activate/deactivate. */
  133.                     gInBackground = !((event->message) & resumeFlag);
  134.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  135.                     DoActivate(FrontWindow());
  136.                     HiliteWindows();
  137.                     break;
  138.             }
  139.             break;
  140.  
  141.         case diskEvt:
  142.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  143.             if (HiWord(event->message) != noErr) {
  144.                 SetPt(&pt, kDILeft, kDITop);
  145.                 err = DIBadMount(pt, event->message);
  146.             }
  147.             break;        /* It is not a bad idea to at least call DIBadMount
  148.                         ** in response to a diskEvt, so that the user can
  149.                         ** format a floppy. */
  150.     }
  151.  
  152.     DoCursor();
  153.     DoAdjustMenus();
  154.  
  155.     window = CTETargetInfo(&teHndl, &rct);
  156.     if (window) {
  157.         if (rct.left < -8192) {
  158.             GetPort(&oldPort);
  159.             SetPort(window);
  160.             SetOrigin(-16384, 0);
  161.             CTEIdle();
  162.             SetOrigin(0, 0);
  163.             SetPort(oldPort);
  164.         }
  165.         else {
  166.             BeginContent(window);
  167.             CTEIdle();
  168.             EndContent(window);
  169.         }
  170.     }
  171. }
  172.  
  173.  
  174.  
  175. /*****************************************************************************/
  176.  
  177.  
  178.  
  179. /* •• Called by DTS.Lib..framework. •• */
  180.  
  181. /* This is called when a window is activated or deactivated. */
  182.  
  183. #pragma segment Main
  184. void    DoActivate(WindowPtr window)
  185. {
  186.     RgnHandle    rgn, oldClip;
  187.     Point        pt;
  188.  
  189.     NotifyCancel();
  190.  
  191.     if (IsAppWindow(window)) {
  192.         SetPort(window);
  193.         DoCtlActivate(window);
  194.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  195.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  196.         DiffRgn(rgn, ((WindowPeek)window)->contRgn, rgn);
  197.             /* Don't draw any part that's already destined to draw due to an update event.
  198.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  199.             ** flickering. */
  200.         BeginContent(window);
  201.         pt.h = pt.v = 0;
  202.         GlobalToLocal(&pt);
  203.         OffsetRgn(rgn, pt.h, pt.v);
  204.         GetClip(oldClip = NewRgn());
  205.         SetClip(rgn);
  206.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  207.         SetClip(oldClip);
  208.         DisposeRgn(oldClip);
  209.         DisposeRgn(rgn);
  210.         EndContent(window);
  211.     }
  212. }
  213.  
  214.  
  215.  
  216.